﻿using HardcoreGame.Common.CustomSets;
using HardcoreGame.Common.Helpers;
using HardcoreGame.Content.Projectiles.Sets.Acid;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ReLogic.Content;
using System;
using Terraria;
using Terraria.DataStructures;
using Terraria.ID;
using Terraria.ModLoader;

namespace HardcoreGame.Content.Items.Weapons.Sets.Acid
{
    public class AcidRainBow : ModItem
    {
        public static Lazy<Asset<Texture2D>> glowmask;
        public override void Unload()
        {
            glowmask = null;
        }
        private int AttackType;
        public override void SetStaticDefaults()
        {
            CustomItemSets.AcidWeapon[Type] = true;
        }
        public override void SetDefaults()
        {
            Item.damage = 5;
            Item.shoot = ProjectileID.WoodenArrowFriendly;
            Item.shootSpeed = 10f;
            Item.useAmmo = AmmoID.Arrow;
            Item.DamageType = DamageClass.Ranged;
            Item.noMelee = true;
            Item.width = 60;
            Item.height = 60;
            Item.useAnimation = 16;
            Item.useTime = 4;
            Item.reuseDelay = 20;
            Item.useStyle = ItemUseStyleID.Shoot;
            Item.knockBack = 4f;
            Item.rare = ItemRarityID.Blue;
            Item.autoReuse = true;
            Item.UseSound = SoundID.Item5;
            Item.value = Item.sellPrice(0, 1, 55, 0);
            if (!Main.dedServ)
            {
                glowmask = new Lazy<Asset<Texture2D>>(() => ModContent.Request<Texture2D>(Texture + "_Glow", (AssetRequestMode)2));
            }
        }
        public override Vector2? HoldoutOffset()
        {
            return new Vector2?(new Vector2(-6f, 0f));
        }
        public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback)
        {
            AttackType++;
            Vector2 perturbedSpeed2 = Utils.RotatedByRandom(velocity, (double)(MathHelper.ToRadians(4f) * 2f));
            Projectile.NewProjectile(source, position, perturbedSpeed2, ModContent.ProjectileType<AcidRainArrow>(), damage, knockback, player.whoAmI, 0f, 0f, 0f);
            if (AttackType == 20)
            {
                AttackType = 0;
            }
            return false;
        }
        public override void PostDrawInWorld(SpriteBatch spriteBatch, Color lightColor, Color alphaColor, float rotation, float scale, int whoAmI)
        {
            MyUtils.BasicInWorldGlowmask(Item, spriteBatch, (Texture2D)glowmask.Value, Color.White, rotation, scale);
        }
    }
}
